#!/bin/bash
#pMusic - build gtkdialog xml code
#GPL - Copyright Sigmund Berglund

export TEXTDOMAIN=pmusic
export OUTPUT_CHARSET=UTF-8
[[ "$*" = *'-eq'* ]] && GUI_PEQUALIZER="`/usr/local/pequalizer/pequalizer -e 2> /dev/null`" #for those that has eq built in main gui

S='
<timer visible="false" milliseconds="true" interval="'$UPDATE_INTERVAL'">
 <variable export="false">TIMER</variable>
 <action>nice -n 18 '$APPDIR'/func_progressbar</action>
 <action>refresh:PROGRESS</action>
 <action>refresh:STATUSBAR</action>
 <action>refresh:UPDATE_SOURCELIST</action>

 ###update further items if file UPDATE_GUI is true.
 ###The below lines was previous a checkbox like UPDATE_SOURCELIST, but because fast doubleclickinging to add tracks lead to file UPDATE_GUI never switched to false --> no rerendering

 <action condition="file_is_false( '$WORKDIR'/UPDATE_GUI )" function="break">""</action>
 <action>refresh:SVG_NOWPLAYING</action>
 <action>refresh:BUTTON_PLAY</action> ###play or pause icon
 <action>refresh:WINDOW_TITLE</action>'
 [[ "$*" != *skip_albumart* ]] && S=$S'<action>refresh:ARTWORK</action>'
 S=$S'<action>refresh:NOTEBOOK_MAINGUI</action>
 <action>refresh:YOUTUBE_OUTFILE</action>
 <action>echo false > '$WORKDIR'/UPDATE_GUI</action>

 <action condition="file_is_false( '$WORKDIR'/UPDATE_PLAYLIST )" function="break">""</action>
 <action>refresh:PLAYLIST</action>
 <action>echo false > '$WORKDIR'/UPDATE_PLAYLIST</action>
</timer>

###switch that updates sourcelist and searchfield independent of user interaction
<checkbox visible="false">
 <variable>UPDATE_SOURCELIST</variable>
 <input file>'$WORKDIR'/UPDATE_SOURCELIST</input>
 <action>if true refresh:SOURCE</action>
 <action>if true refresh:SEARCH</action>
 <action>if true echo false > '$WORKDIR'/UPDATE_SOURCELIST</action>
 <action>if true refresh:UPDATE_SOURCELIST</action>
</checkbox>'

if [[ "$*" != *skip_albumart* ]]; then
	S=$S'<button visible="false">
	 <variable>ALBUMART_SEARCH_ACTIVATE</variable>
	 <action condition="active_is_false(SEARCH_ALBUMART)" function="break">""</action>
	 <action>refresh:ALBUMART_SEARCH_PREV</action>
	 <action>refresh:ALBUMART_SEARCH_NEXT</action>
	 <action>refresh:ALBUMART_SEARCH1</action>
	 <action>refresh:ALBUMART_SEARCH2</action>
	 <action>refresh:ALBUMART_SEARCH3</action>
	 <action>refresh:ALBUMART_SEARCH4</action>
	 <action>refresh:ALBUMART_SEARCH5</action>
	 <action>refresh:ALBUMART_SEARCH6</action>
	 <action>refresh:ALBUMART_SEARCH7</action>
	 <action>refresh:ALBUMART_SEARCH8</action>
	 <action>refresh:ALBUMART_SEARCH9</action>
	 <action>refresh:ALBUMART_SEARCH10</action>
	 <action>refresh:ALBUMART_SEARCH11</action>
	 <action>refresh:ALBUMART_SEARCH12</action>
	 <action>refresh:ALBUMART_SEARCH13</action>
	 <action>refresh:ALBUMART_SEARCH14</action>
	 <action>refresh:ALBUMART_SEARCH15</action>
	 <action>refresh:ALBUMART_SEARCH16</action>
	 <action>refresh:ALBUMART_SEARCH17</action>
	 <action>refresh:ALBUMART_SEARCH18</action>
	 <action>refresh:ALBUMART_SEARCH19</action>
	 <action>refresh:ALBUMART_SEARCH20</action>
	</button>'
fi

GUI_PROGRESS="$S"

GUI_PROGRESSBAR='
<hscale draw-value="false" block-function-signals="true" update-policy="1" scale-step="1" scale-min="0" scale-max="100"> ###update-policy: 0=constantly 1=button-activated 2=delayed
 <variable>PROGRESS</variable>
 <input file>'$WORKDIR'/PERCENT_BAR</input>
 <action signal="button-press-event">disable:TIMER</action>
 <action>'$APPDIR'/func_player -jump_to_percent -skip_update $PROGRESS</action>
 <action>enable:TIMER</action>
</hscale>'

GUI_STATUSBAR='
<statusbar>
 <variable>STATUSBAR</variable>
 <input file>'$WORKDIR'/statusbar</input>
</statusbar>'

GUI_MSG='
<hbox '$ST'>
 <text xalign="0,05" width-chars="25" '$ST'><label>'$(gettext 'Added track not found in the music database. Scan its source directory?')'</label></text>
 <button image-position="2">
  <input file stock="gtk-apply"></input>
  <label>'$(gettext 'Scan')'</label>
  <action>TMP="`cat '$WORKDIR'/source_checked`"; '$APPDIR'/func_index -msg_quick_update "${TMP%/*}" &</action>
 </button>
 <button image-position="2">
  <input file stock="gtk-close"></input>
  <label>'$(gettext 'Skip')'</label>
  <action>echo 0 > '$WORKDIR'/maingui_notebook_page</action>
  <action>[ -f '$HOME'/.pmusic/nowplaying_albumart.jpg ] && cp -f '$HOME'/.pmusic/nowplaying_albumart.jpg '$WORKDIR'/albumart.jpg || cp -f "'$APPDIR'/themes/'$THEME'/album_art.svg" '$WORKDIR'/albumart.jpg</action>
  <action>refresh:NOTEBOOK_MAINGUI</action>
  <action>refresh:ARTWORK</action>
 </button>
 <vseparator '$SF'></vseparator>
</hbox>
'

GUI_MSG2='
<text xalign="0,05" '$ST'><label>"'$(gettext 'Scanning for local music')'
'$(gettext 'Please wait')'..."</label></text>
'

GUI_MSG3='
<hbox '$ST'>
 <vbox '$ST'>
  <text xalign="0" '$ST'><label>"'$(gettext ' Playing a youtube stream
 functionality is limited')'"</label></text>
  <entry>
   <variable>YOUTUBE_OUTFILE</variable>
   <input file>'$WORKDIR'/YOUTUBE_OUTFILE</input>
   <action signal="activate">'$APPDIR'/func -youtube_download "$YOUTUBE_OUTFILE" &</action>
  </entry>
 </vbox>
 <button image-position="2">
  <input file stock="gtk-download"></input>
  <label>'$(gettext 'Download')'</label>
  <action>'$APPDIR'/func -youtube_download "$YOUTUBE_OUTFILE" &</action>
 </button>
 <vseparator '$SF'></vseparator>
</hbox>
'
